import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ConfigService } from '@nestjs/config';
import { BaseService } from '@wwjCommon/base/base.service';
import { CacheService } from '@wwjCommon/cache/cache.service';
import { LoggingService } from '@wwjCommon/logging/logging.service';
import { UploadService } from '@wwjVendor/upload/upload.service';
import { PayService } from '@wwjVendor/pay/pay.service';
import { SmsService } from '@wwjVendor/sms/sms.service';
import { NoticeService } from '@wwjVendor/notice/notice.service';

@Injectable()
export class MenuService extends BaseService<any> {
  private readonly logger = new Logger(MenuService.name);

  constructor(
    @InjectRepository(Object)
    protected readonly repository: Repository<any>,
    private readonly cacheService: CacheService,
    private readonly configService: ConfigService,
    private readonly loggingService: LoggingService,
    private readonly uploadService: UploadService,
    private readonly payService: PayService,
    private readonly smsService: SmsService,
    private readonly noticeService: NoticeService,
  ) {
    super(repository);
  }

  /**
   * add
   * 对应 PHP: MenuService_admin::add()
   * 逻辑类型: undefined - undefined
   */
  async add(data: any[]) {
    // 基于PHP真实逻辑: add
    // PHP原文: $menu = $this->find($data[ 'menu_key' ], $data[ 'app_type' ]);         if (!$menu->isEmpty()) throw new AdminException('validate_menu.exit_menu_key');...
const menu = this.find(data[ 'menu_key' ), data[ 'app_type' )];
        if (!menu.isEmpty()) throw new AdminBusinessException('validate_menu.exit_menu_key'];//创建失败

        data[ 'source' ] = MenuDict.CREATE;
        const res = this.model.create(data);
        if (!res) throw new AdminBusinessException('ADD_FAIL');//创建失败

        Cache.tag(self.cache_tag_name).clear(];
        return res;
    }


    /**
     * 更新菜单
     * @param string app_type
     * @param string menu_key
     * @param data
     * @return SysMenu
     */
    async edit(string app_type, string menu_key, data)
    {
        const where = [
            [ 'app_type', '=', app_type ],
            [ 'menu_key', '=', menu_key )
        ];
        const res = this.model.update(data, where);
        Cache.tag(self.cache_tag_name).clear(];
        return res;
    }

    /**
     * 获取信息
     * @param string app_type
     * @param string menu_key
     * @return */
    async get(string app_type, string menu_key)
    {
        return this.model.where([ [ 'app_type', '=', app_type ], [ 'menu_key', '=', menu_key ) )).findOrEmpty().toArray(];
    }

    /**
     * @param string menu_key
     * @param string app_type
     * @return SysMenu|array|mixed|Model
     */
    async find(string menu_key, string app_type = '')
    {
        const where = [
            [ 'menu_key', '=', menu_key )
        ];
        if (!!app_type)) {
            where[] = [ 'app_type', '=', app_type ];
  }

  /**
   * edit
   * 对应 PHP: MenuService_admin::edit()
   * 逻辑类型: undefined - undefined
   */
  async edit(app_type: any[], menu_key: any[], data: any[]) {
    // 基于PHP真实逻辑: edit
    // PHP原文: $where = array(             [ 'app_type', '=', $app_type ],             [ 'menu_key', '=', $menu_key ]         );         $res = $this->model->update(...
const where = [
            [ 'app_type', '=', app_type ],
            [ 'menu_key', '=', menu_key )
        ];
        const res = this.model.update(data, where);
        Cache.tag(self.cache_tag_name).clear(];
        return res;
    }

    /**
     * 获取信息
     * @param string app_type
     * @param string menu_key
     * @return */
    async get(string app_type, string menu_key)
    {
        return this.model.where([ [ 'app_type', '=', app_type ], [ 'menu_key', '=', menu_key ) )).findOrEmpty().toArray(];
    }

    /**
     * @param string menu_key
     * @param string app_type
     * @return SysMenu|array|mixed|Model
     */
    async find(string menu_key, string app_type = '')
    {
        const where = [
            [ 'menu_key', '=', menu_key )
        ];
        if (!!app_type)) {
            where[] = [ 'app_type', '=', app_type ];
  }

  /**
   * get
   * 对应 PHP: MenuService_admin::get()
   * 逻辑类型: undefined - undefined
   */
  async get(app_type: string, menu_key: string) {
    // 基于PHP真实逻辑: get
    // PHP原文: return $this->model->where([ [ 'app_type', '=', $app_type ], [ 'menu_key', '=', $menu_key ] ])->findOrEmpty()->toArray();     }      /**      * @param...
return this.model.where([ [ 'app_type', '=', app_type ], [ 'menu_key', '=', menu_key ) )).findOrEmpty().toArray(];
    }

    /**
     * @param string menu_key
     * @param string app_type
     * @return SysMenu|array|mixed|Model
     */
    async find(string menu_key, string app_type = '')
    {
        const where = [
            [ 'menu_key', '=', menu_key )
        ];
        if (!!app_type)) {
            where[] = [ 'app_type', '=', app_type ];
  }

  /**
   * findRecord (原方法名: find)
   * 对应 PHP: MenuService_admin::find()
   * 逻辑类型: undefined - undefined
   * 注意: 为避免与BaseService方法冲突，已重命名
   */
  async findRecord(menu_key: string, app_type: string) {
    // 基于PHP真实逻辑: find
    // PHP原文: $where = array(             [ 'menu_key', '=', $menu_key ]         );         if (!empty($app_type)) {             $where[] = [ 'app_type', '=', $app_...
const where = [
            [ 'menu_key', '=', menu_key )
        ];
        if (!!app_type)) {
            where[] = [ 'app_type', '=', app_type ];
  }

  /**
   * del
   * 对应 PHP: MenuService_admin::del()
   * 逻辑类型: undefined - undefined
   */
  async del(app_type: string, menu_key: string) {
    // 基于PHP真实逻辑: del
    // PHP原文: //查询是否有下级菜单或按钮         $menu = $this->find($menu_key, $app_type);         if ($this->model->where([ [ 'parent_key', '=', $menu_key ], [ 'app_type', '=...
//查询是否有下级菜单或按钮
        const menu = this.find(menu_key, app_type];
        if (this.model.where([ [ 'parent_key', '=', menu_key ], [ 'app_type', '=', app_type ) )).count() > 0)
            throw new AdminBusinessException('MENU_NOT_ALLOW_DELETE'];

        const res = menu.delete();
        Cache.tag(self.cache_tag_name).clear(];
        return res;
    }

    /**
     * 通过菜单menu_key获取
     * @param int site_id
     * @param menu_keys
     * @param string app_type
     * @param int is_tree
     * @param string addon 用于检测插件筛选
     * @param int is_button
     * @return mixed
     * @throws DataNotFoundBusinessException
     * @throws DbBusinessException
     * @throws ModelNotFoundBusinessException
     */
    async getMenuListByMenuKeys(int site_id, menu_keys, string app_type, int is_tree = 0, addon = 'all', is_button = 1)
    {
        sort(menu_keys);
        const cache_name = 'menu' . md5(implode("_", menu_keys)) . is_tree . addon . site_id;
        const menu_list = cache_remember(
            cache_name,
            function() use (site_id, menu_keys, app_type, is_tree, addon) {
                const where = [
                    [ 'menu_key', 'in', menu_keys ],
                ];
                const addons = ( this.addonService ).getAddonKeysBySiteId(site_id];
                addons[] = '';

                const delete_menu_addon = [];
                const addon_loader = new DictLoader("Menu");

                if (addon != 'all') {
                    where[] = [ 'addon', '=', addon ];

                    const delete_menu = addon_loader.load([ addon: addon, app_type: app_type ))[ 'delete' ] || [];
                    if (!!delete_menu) && is_[delete_menu)) delete_menu_addon[] = delete_menu;
                } } } else {
                    where[] = [ 'addon', 'in', addons ];

                    foreach (addons as addon) {
                        const delete_menu = addon_loader.load([ addon: addon, app_type: app_type ))[ 'delete' ] || [];
                        if (!!delete_menu) && is_[delete_menu)) delete_menu_addon[] = delete_menu;
                    }
                }

                // 排除插件中delete的菜单
                if (!!delete_menu_addon)) {
                    const delete_intersect = array_intersect(...delete_menu_addon);
                    if (!!delete_intersect)) {
                        where[] = [ 'menu_key', 'not in', delete_intersect ;
  }
                if (!!app_type)) {
                    where[] = [ 'app_type', '=', app_type ];
                }
                return this.model.where(where).order('sort', 'desc').select().toArray(];
  }

  /**
   * getMenuListByMenuKeys
   * 对应 PHP: MenuService_admin::getMenuListByMenuKeys()
   * 逻辑类型: undefined - undefined
   */
  async getMenuListByMenuKeys(site_id: any[], menu_keys: any[], app_type: any[], is_tree: any[], addon: any[], is_button: any[]) {
    // 基于PHP真实逻辑: getMenuListByMenuKeys
    // PHP原文: sort($menu_keys);         $cache_name = 'menu' . md5(implode("_", $menu_keys)) . $is_tree . $addon . $site_id;         $menu_list = cache_remember(   ...
sort(menu_keys);
        const cache_name = 'menu' . md5(implode("_", menu_keys)) . is_tree . addon . site_id;
        const menu_list = cache_remember(
            cache_name,
            function() use (site_id, menu_keys, app_type, is_tree, addon) {
                const where = [
                    [ 'menu_key', 'in', menu_keys ],
                ];
                const addons = ( this.addonService ).getAddonKeysBySiteId(site_id];
                addons[] = '';

                const delete_menu_addon = [];
                const addon_loader = new DictLoader("Menu");

                if (addon != 'all') {
                    where[] = [ 'addon', '=', addon ];

                    const delete_menu = addon_loader.load([ addon: addon, app_type: app_type ))[ 'delete' ] || [];
                    if (!!delete_menu) && is_[delete_menu)) delete_menu_addon[] = delete_menu;
                } } } else {
                    where[] = [ 'addon', 'in', addons ];

                    foreach (addons as addon) {
                        const delete_menu = addon_loader.load([ addon: addon, app_type: app_type ))[ 'delete' ] || [];
                        if (!!delete_menu) && is_[delete_menu)) delete_menu_addon[] = delete_menu;
                    }
                }

                // 排除插件中delete的菜单
                if (!!delete_menu_addon)) {
                    const delete_intersect = array_intersect(...delete_menu_addon);
                    if (!!delete_intersect)) {
                        where[] = [ 'menu_key', 'not in', delete_intersect ;
  }
                if (!!app_type)) {
                    where[] = [ 'app_type', '=', app_type ];
                }
                return this.model.where(where).order('sort', 'desc').select().toArray(];
  }

  /**
   * getAllMenuList
   * 对应 PHP: MenuService_admin::getAllMenuList()
   * 逻辑类型: undefined - undefined
   */
  async getAllMenuList(app_type: any, status: any, is_tree: any, is_button: any) {
    // 基于PHP真实逻辑: getAllMenuList
    // PHP原文: $site_id = $this->site_id;         $cache_name = 'site_menu_api_' . $app_type . '_' . $status . '_' . $is_tree . '_' . $is_button . '_' . $this->site_...
const site_id = this.site_id;
        const cache_name = 'site_menu_api_' . app_type  + '_' . status  + '_' . is_tree  + '_' . is_button  + '_' . this.site_id;
        const menu_list = cache_remember(
            cache_name,
            function() use (status, is_tree, is_button, app_type, site_id) {
                const where = [
                    [ 'app_type', '=', app_type ],
                    [ 'addon', 'in', Object.assign([ '' ), get_site_addons(site_id)) ]
                ];
                if (status != 'all') {
                    where[] = [ 'status', '=', status ];
                }

                // 排除菜单
                const delete_menu_addon = [];
                const addon_loader = new DictLoader("Menu");
                foreach (get_site_addons(site_id) as addon) {
                    const delete_menu = addon_loader.load([ addon: addon, app_type: app_type ))[ 'delete' ] || [];
                    if (!!delete_menu) && is_[delete_menu)) delete_menu_addon[] = delete_menu;
                }
                if (!!delete_menu_addon)) {
                    const delete_intersect = array_intersect(...delete_menu_addon);
                    if (!!delete_intersect)) {
                        where[] = [ 'menu_key', 'not in', delete_intersect ;
  }
                return this.model.where(where).order('sort desc').select().toArray(];
  }

  /**
   * moveChildrenToParent
   * 对应 PHP: MenuService_admin::moveChildrenToParent()
   * 逻辑类型: undefined - undefined
   */
  async moveChildrenToParent(menus: any[]) {
    // 基于PHP真实逻辑: moveChildrenToParent
    // PHP原文: $menuKeyMap = [];         //处理整个菜单结构，建立menu_key映射         $flattenMenus = function (&$list) use (&$flattenMenus, &$menuKeyMap) {             foreach (...
const menuKeyMap = [];
        //处理整个菜单结构，建立menu_key映射
        const flattenMenus = function (&list) use (&flattenMenus, &menuKeyMap) {
            foreach (list as &item) {
                if (!!item[ 'menu_key' ))) {
                    menuKeyMap[item[ 'menu_key' ]] = &item;
                }
                if (typeof item[ 'children' )) && is_[item[ 'children' ))) {
                    flattenMenus(item[ 'children' );
  }
  }

  /**
   * getApiListByMenuKeys
   * 对应 PHP: MenuService_admin::getApiListByMenuKeys()
   * 逻辑类型: undefined - undefined
   */
  async getApiListByMenuKeys(menu_keys: any[], app_type: any[]) {
    // 基于PHP真实逻辑: getApiListByMenuKeys
    // PHP原文: sort($menu_keys);         $cache_name = 'api' . md5(implode("_", $menu_keys));         return cache_remember(             $cache_name,             fun...
sort(menu_keys);
        const cache_name = 'api' . md5(implode("_", menu_keys)];
        return cache_remember(
            cache_name,
            function() use (menu_keys, app_type) {
                const where = [
                    [ 'menu_key', 'in', menu_keys ]
                ];
                if (!!app_type)) {
                    where[] = [ 'app_type', '=', app_type ];
                }
                const menu_list = ( this.sysMenuService ).where(where).order('sort', 'desc').column('api_url,methods');
                foreach (menu_list as v) {
                    auth_menu_list[ v[ 'methods' ] ][] = v[ 'api_url' ];
                }
                return auth_menu_list || [];
  }

  /**
   * getButtonListBuMenuKeys
   * 对应 PHP: MenuService_admin::getButtonListBuMenuKeys()
   * 逻辑类型: undefined - undefined
   */
  async getButtonListBuMenuKeys(menu_keys: any[], app_type: any[]) {
    // 基于PHP真实逻辑: getButtonListBuMenuKeys
    // PHP原文: sort($menu_keys);         $cache_name = 'button' . md5(implode("_", $menu_keys));         return cache_remember(             $cache_name,             ...
sort(menu_keys);
        const cache_name = 'button' . md5(implode("_", menu_keys)];
        return cache_remember(
            cache_name,
            function() use (menu_keys, app_type) {
                const where = [
                    [ 'menu_key', 'in', menu_keys ],
                    [ 'menu_type', '=', MenuTypeDict.BUTTON ]
                ];
                if (!!app_type)) {
                    where[] = [ 'app_type', '=', app_type ];
                }
                return this.model.where(where).order('sort', 'desc').column('menu_key');
  }

  /**
   * getAllApiList
   * 对应 PHP: MenuService_admin::getAllApiList()
   * 逻辑类型: undefined - undefined
   */
  async getAllApiList(app_type: any, status: any) {
    // 基于PHP真实逻辑: getAllApiList
    // PHP原文: $cache_name = 'all_api' . $app_type . '_' . $status;         return cache_remember(             $cache_name,             function() use ($status, $app...
const cache_name = 'all_api' . app_type  + '_' . status;
        return cache_remember(
            cache_name,
            function() use (status, app_type) {
                const where = [
                    [ 'api_url', '<>', '' ],
                    [ 'app_type', '=', app_type ],
                ];
                if (status != 'all') {
                    where[] = [ 'status', '=', status ];
                }
                const menu_list = this.model.where(where).order('sort', 'desc').column('methods, api_url'];
                const auth_menu_list = [);
                foreach (menu_list as v) {
                    auth_menu_list[ v[ 'methods' ] ][] = v[ 'api_url' ];
                }
                return auth_menu_list;
  }

  /**
   * getAllMenuIdsByAppType
   * 对应 PHP: MenuService_admin::getAllMenuIdsByAppType()
   * 逻辑类型: undefined - undefined
   */
  async getAllMenuIdsByAppType(app_type: string, status: string) {
    // 基于PHP真实逻辑: getAllMenuIdsByAppType
    // PHP原文: $cache_name = 'menu_id_by_app_type_' . $app_type;         return cache_remember(             $cache_name,             function() use ($app_type, $stat...
const cache_name = 'menu_id_by_app_type_' . app_type;
        return cache_remember(
            cache_name,
            function() use (app_type, status) {
                const where = [
//
                    [ 'app_type', '=', app_type ],
                ];
                if (status != 'all') {
                    where[] = [ 'status', '=', status ];
                }
                return this.model.where(where).order('sort desc').column('menu_key');
  }

  /**
   * getAllButtonList
   * 对应 PHP: MenuService_admin::getAllButtonList()
   * 逻辑类型: undefined - undefined
   */
  async getAllButtonList(app_type: any, status: any, is_tree: any) {
    // 基于PHP真实逻辑: getAllButtonList
    // PHP原文: $cache_name = 'menu_api_' . $app_type . '_' . $status . '_' . $is_tree;         return cache_remember(             $cache_name,             function()...
const cache_name = 'menu_api_' . app_type  + '_' . status  + '_' . is_tree;
        return cache_remember(
            cache_name,
            function() use (status, is_tree, app_type) {
                const where = [
                    [ 'menu_type', '=', MenuTypeDict.BUTTON ],
                    [ 'app_type', '=', app_type ],
                ];
                if (status != 'all') {
                    where[] = [ 'status', '=', status ];
                }
                return this.model.where(where).order('sort', 'desc').column('menu_key');
  }

  /**
   * menuToTree
   * 对应 PHP: MenuService_admin::menuToTree()
   * 逻辑类型: undefined - undefined
   */
  async menuToTree(list: any, pk: any, pid: any, child: any, button_name: any, root: any, is_button: any) {
    // 基于PHP真实逻辑: menuToTree
    // PHP原文: // 创建Tree         $tree = array();         if (is_array($list)) {             // 创建基于主键的数组引用             $refer = array();             foreach ($list ...
// 创建Tree
        const tree = [];
        if (is_[list)) {
            // 创建基于主键的数组引用
            const refer = [];
            foreach (list as key => data) {
                refer[ data[ pk ] ] =& list[ key ];
            }
            foreach (list as key => data) {
                // 判断是否存在parent
                const parent_id = data[ pid ];
                if (root == parent_id) {
                    tree[] =& list[ key ];
                } } } else {
                    if (typeof refer[ parent_id ))) {
                        const parent =& refer[ parent_id ];
                        if (list[ key )[ 'menu_type' ) == 2 && is_button == 1) {
                            parent[ button_name ][] =& list[ key ][ 'menu_key' ];
                        } } } else {
                            parent[ child ][] =& list[ key ;
  }
                }
            }
  }

  /**
   * getFullRouterPath
   * 对应 PHP: MenuService_admin::getFullRouterPath()
   * 逻辑类型: undefined - undefined
   */
  async getFullRouterPath(menu_key: any) {
    // 基于PHP真实逻辑: getFullRouterPath
    // PHP原文: $menu = $this->model->where([ [ 'menu_key', '=', $menu_key ] ])->findOrEmpty($menu_key);         if ($menu->isEmpty()) return '';         $parents = [...
const menu = this.model.where([ [ 'menu_key', '=', menu_key ) )).findOrEmpty(menu_key);
        if (menu.isEmpty()) return '';
        const parents = [];
        this.getParentDirectory(menu, parents];
        const parents = array_reverse(parents];
        const router_path = implode('/', parents);
        if (!!router_path)) {
            router_path  +=  '/' . menu[ 'router_path' ];
  }

  /**
   * getParentDirectory
   * 对应 PHP: MenuService_admin::getParentDirectory()
   * 逻辑类型: undefined - undefined
   */
  async getParentDirectory(menu: any, parents: any) {
    // 基于PHP真实逻辑: getParentDirectory
    // PHP原文: if (!$menu->isEmpty() && !empty($menu[ 'parent_key' ])) {             $parent_menu = $this->model->where([ [ 'menu_key', '=', $menu[ 'parent_key' ] ] ...
if (!menu.isEmpty() && !!menu[ 'parent_key' ))) {
            const parent_menu = this.model.where([ [ 'menu_key', '=', menu[ 'parent_key' ] ) )).findOrEmpty(];
            if (!!parent_menu)) {
                if (!!parent_menu[ 'router_path' ))) parents[] = parent_menu[ 'router_path' ];
                this.getParentDirectory(parent_menu, parents);
            }
  }

  /**
   * getApiListBySystem
   * 对应 PHP: MenuService_admin::getApiListBySystem()
   * 逻辑类型: undefined - undefined
   */
  async getApiListBySystem(app_type: any[], addons: any[]) {
    // 基于PHP真实逻辑: getApiListBySystem
    // PHP原文: sort($addons);         $cache_name = 'system_menu_api_' . $app_type . implode("_", $addons);         return cache_remember(             $cache_name,  ...
sort(addons];
        const cache_name = 'system_menu_api_' . app_type . implode("_", addons);
        return cache_remember(
            cache_name,
            function() use (app_type, addons) {
                addons[] = '';
                const where = [
                    [ 'addon', 'in', addons ]
                ];
                if (!!app_type)) {
                    where[] = [ 'app_type', '=', app_type ];
                }
                const menu_list = ( this.sysMenuService ).where(where).order('sort', 'desc').column('api_url,methods');
                foreach (menu_list as v) {
                    auth_menu_list[ v[ 'methods' ] ][] = v[ 'api_url' ];
                }
                return auth_menu_list || [];
  }

  /**
   * getMenuListBySystem
   * 对应 PHP: MenuService_admin::getMenuListBySystem()
   * 逻辑类型: undefined - undefined
   */
  async getMenuListBySystem(app_type: any[], addons: any[], is_tree: any[], is_button: any[], status: any[]) {
    // 基于PHP真实逻辑: getMenuListBySystem
    // PHP原文: sort($addons);         $cache_name = 'menu' . md5(implode("_", $addons)) . $is_tree . $status;         $menu_list = cache_remember(             $cache...
sort(addons);
        const cache_name = 'menu' . md5(implode("_", addons)) . is_tree . status;
        const menu_list = cache_remember(
            cache_name,
            function() use (addons, app_type, is_tree, status) {
                const where = [
                    [ 'addon', 'in', addons ]
                ];
                if (!!app_type)) {
                    where[] = [ 'app_type', '=', app_type ];
                }
                if (status != 'all') where[] = [ 'status', '=', status ];
                // 排除插件中delete的菜单
                const delete_menu_addon = [];
                const addon_loader = new DictLoader("Menu");
                foreach (addons as addon) {
                    const delete_menu = addon_loader.load([ addon: addon, app_type: app_type ))[ 'delete' ] || [];
                    if (!!delete_menu) && is_[delete_menu)) delete_menu_addon[] = delete_menu;
                }
                if (!!delete_menu_addon)) {
                    const delete_intersect = array_intersect(...delete_menu_addon);
                    if (!!delete_intersect)) {
                        where[] = [ 'menu_key', 'not in', delete_intersect ;
  }
                return this.model.where(where).order('sort', 'desc').select().toArray(];
  }

  /**
   * getMenuKeysBySystem
   * 对应 PHP: MenuService_admin::getMenuKeysBySystem()
   * 逻辑类型: undefined - undefined
   */
  async getMenuKeysBySystem(app_type: any[], addons: any[]) {
    // 基于PHP真实逻辑: getMenuKeysBySystem
    // PHP原文: sort($addons);         $cache_name = 'menu_keys_' . $app_type . implode("_", $addons);         return cache_remember(             $cache_name,        ...
sort(addons];
        const cache_name = 'menu_keys_' . app_type . implode("_", addons);
        return cache_remember(
            cache_name,
            function() use (app_type, addons) {
                addons[] = '';
                const where = [
                    [ 'addon', 'in', addons ]
                ];
                if (!!app_type)) {
                    where[] = [ 'app_type', '=', app_type ];
                }
                return ( this.sysMenuService ).where(where).order('sort', 'desc').column('menu_key');
  }

  /**
   * getSystemMenu
   * 对应 PHP: MenuService_admin::getSystemMenu()
   * 逻辑类型: undefined - undefined
   */
  async getSystemMenu(status: any, is_tree: any, is_button: any) {
    // 基于PHP真实逻辑: getSystemMenu
    // PHP原文: if ($is_button == 0) {             $where = [                 [ 'menu_type', 'in', [ 0, 1 ] ]             ];...
if (is_button == 0) {
            const where = [
                [ 'menu_type', 'in', [ 0, 1 ] ]
            ];
  }

  /**
   * getAddonMenu
   * 对应 PHP: MenuService_admin::getAddonMenu()
   * 逻辑类型: undefined - undefined
   */
  async getAddonMenu(app_key: any, status: any, is_tree: any, is_button: any) {
    // 基于PHP真实逻辑: getAddonMenu
    // PHP原文: if ($is_button == 0) {             $where = [                 [ 'menu_type', 'in', [ 0, 1 ] ]             ];...
if (is_button == 0) {
            const where = [
                [ 'menu_type', 'in', [ 0, 1 ] ]
            ];
  }

  /**
   * getMenuByTypeDir
   * 对应 PHP: MenuService_admin::getMenuByTypeDir()
   * 逻辑类型: undefined - undefined
   */
  async getMenuByTypeDir(addon: string) {
    // 基于PHP真实逻辑: getMenuByTypeDir
    // PHP原文: $cache_name = 'menu_api_by_type_dir' . $addon;         $menu_list = cache_remember(             $cache_name,             function() use ($addon) {    ...
const cache_name = 'menu_api_by_type_dir' . addon;
        const menu_list = cache_remember(
            cache_name,
            function() use (addon) {
                const where = [
                    [ 'menu_type', '=', 0 ],
                    [ 'app_type', '=', 'site' ]
                ];
                //查询应用
                where[] = [ 'addon', '=', addon == 'system' ? '' : addon ];
                return ( this.sysMenuService ).where(where).order('sort desc').select().toArray(];
  }
}
